from app.core.config import settings 
from app.services.db_service_interface import DBServiceInterface
from typing import TypeVar, Type

T = TypeVar('T')

def get_db_service() -> DBServiceInterface[T]:
    """根据配置返回数据库服务实例"""
    if settings.DB_TYPE.lower() == "postgresql":
        from app.services.postgres_service import postgres_service
        if postgres_service is None:
            # 如果实例为None，创建一个新实例
            from app.services.postgres_service import PostgresService
            return PostgresService()
        return postgres_service
    else:
        from app.services.sqlite_service import sqlite_service
        if sqlite_service is None:
            # 如果实例为None，创建一个新实例
            from app.services.sqlite_service import SQLiteService
            return SQLiteService()
        return sqlite_service